package com.longcai.controller.nearbyshop;


import com.longcai.bean.ApiResult;
import com.longcai.bean.PageHelper;
import com.longcai.entity.customer.ClyjUser;
import com.longcai.entity.nearby.ClyjNearbyGoodsType;
import com.longcai.entity.nearby.ClyjNearbyShopsScheme;
import com.longcai.page.table.PageTableResponse;
import com.longcai.service.nearbyshop.ClyjNearbyShopsSchemeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 附近商铺外卖方案 前端控制器
 * </p>
 *
 * @author M
 * @since 2019-04-25
 */
@RestController
@RequestMapping("/clyjNearbyShopsScheme")
public class ClyjNearbyShopsSchemeController {

    @Autowired
    private ClyjNearbyShopsSchemeService clyjNearbyShopsSchemeService;

    /**
     * 外卖方案列表
     *
     * @param clyjNearbyShopsScheme
     * @param pageHelper
     * @return
     */
    @ApiOperation(value = "外卖方案列表")
    @GetMapping(value = "/schemeLists")
    public PageTableResponse schemeLists(ClyjNearbyShopsScheme clyjNearbyShopsScheme, PageHelper pageHelper) {
        return this.clyjNearbyShopsSchemeService.schemeLists(clyjNearbyShopsScheme, pageHelper);
    }


    /**
     * 根据id获取外卖方案
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id获取外卖方案")
    @GetMapping("/{id}")
    @PreAuthorize("hasAuthority('scheme:query')")
    public ApiResult getSchemeInfo(@PathVariable String id) {

        return this.clyjNearbyShopsSchemeService.getSchemeInfo(id);
    }

    /**
     * 新增外卖方案
     *
     * @param clyjNearbyShopsScheme
     * @return
     */
    @PostMapping(value = "/saveScheme")
    @ApiOperation(value = "新增外卖方案")
    @PreAuthorize("hasAuthority('scheme:add')")
    public ApiResult saveScheme(@RequestBody ClyjNearbyShopsScheme clyjNearbyShopsScheme) {
        //判断id
        if (clyjNearbyShopsScheme.getId() == null || clyjNearbyShopsScheme.getId().equals("")) {
            return clyjNearbyShopsSchemeService.saveScheme(clyjNearbyShopsScheme);
        } else {
            this.clyjNearbyShopsSchemeService.updateScheme(clyjNearbyShopsScheme);
        }

        return null;
    }


    /**
     * 删除外卖方案
     *
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除外卖方案")
    @PreAuthorize("hasAuthority('scheme:delete')")
    public ApiResult delete(@PathVariable String id) {

        return this.clyjNearbyShopsSchemeService.deleteById(id);
    }

}

